void main() {
  // Data Types
  // Number String Boolean List Map Dynamic

  String name = "john Doe";
  print("$name");

  int age = 45;
  print("$age");

  double percentage = 69.0;
  print("$percentage");

  bool isOpen = true;
  print("$isOpen");

  dynamic fullname = "John Elder";
  print("$fullname");
  fullname = 1;
  print("$fullname");

  var students = ["Jack", "Eloge", "John", "Fiston"];

  students.add("Mary");

  students[2] = "Mark";

  students.insert(1, "Eustache");

  students.insertAll(1, ["Rose", "Gloria", "Blaise", "Festo"]);

  var mixedList = [1, 2, 3, "John", "Bob"];

  mixedList.remove("Bob");
  print(mixedList);

  mixedList.removeAt(2);
  print(mixedList);

  print(students);

  //  二分搜索
  List<int> scores = [50, 59, 75, 78, 2, 4, 5, 6, 78];
  var target = 78;

  var index = binarySearch(scores, target);
  if (index != -1) {
    print("找到target: ${target}的index了: ${index}");
    print(scores[index]);
  } else {
    print("没找到");
  }

  var toppings = {"John": "Pepperoni", "Mary": "Cheese"};
  print(toppings);

  print(toppings.values);
  print(toppings.keys);
  print(toppings.length);
  toppings.addAll({"Shared": "Damn", "Job": "None"});

  print("Add: $toppings");

  toppings.remove("Mary");
  print("Remove: $toppings");

  toppings.clear();
  print("Clear: $toppings");

  // 唯一出现
  Set<String> names = {"mario", "mark", "damn"};

  names.addAll({"mark", "fish"});
  print(names);
}

// 二分搜索
int binarySearch(List<int> scores, int target) {
  var low = 0;
  var high = scores.length - 1;

  while (low <= high) {
    // 正确计算中间位置：(low + high) ~/ 2
    var mid = (low + high) ~/ 2;

    if (target == scores[mid]) {
      return mid;
    } else if (target < scores[mid]) {
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  // 没找到
  return -1;
}
